﻿using System;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Search;

namespace MetroGA.Win8.Lib
{
	internal static class PathHelper
	{
		public async static Task<bool> FolderExists(this StorageFolder storageFolder, string folder)
		{
			var queryOpt = new QueryOptions
				{
					ApplicationSearchFilter = "system.filename:\"" + folder + "\"",
					FolderDepth = FolderDepth.Shallow,
					IndexerOption = IndexerOption.UseIndexerWhenAvailable
				};

			var queryFolder = storageFolder.CreateFolderQueryWithOptions(queryOpt);
			return (await queryFolder.GetItemCountAsync()) > 0;
		}

		public async static Task<bool> FileExists(this StorageFolder storageFolder, string file)
		{
			var queryOpt = new QueryOptions
				{
					ApplicationSearchFilter = "system.filename:\"" + file + "\"",
					FolderDepth = FolderDepth.Shallow,
					IndexerOption = IndexerOption.UseIndexerWhenAvailable
				};

			var queryFile = storageFolder.CreateFileQueryWithOptions(queryOpt);
			return (await queryFile.GetItemCountAsync()) > 0;
		}
	}
}